package com.wnhz.work.jy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.CouponBean;

import java.util.List;

/**
 * Created by Administrator on 2016/9/10 0010.
 */
public class CouponAdapter extends BaseAdapter {
    private Context context;
    private List<CouponBean> couponList;

    public CouponAdapter(Context context, List<CouponBean> couponList) {
        this.context = context;
        this.couponList = couponList;

    }

    @Override
    public int getCount() {
        return couponList.size();
    }

    @Override
    public Object getItem(int position) {
        return couponList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CouponViewHolder viewHolder = new CouponViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.coupon_item, null);
            viewHolder.tv_type = (TextView) convertView.findViewById(R.id.tv_type);
            viewHolder.tv_number = (TextView) convertView.findViewById(R.id.tv_number);
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            viewHolder.tv_meet = (TextView) convertView.findViewById(R.id.tv_meet);
            viewHolder.tv_use = (TextView) convertView.findViewById(R.id.tv_use);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (CouponViewHolder) convertView.getTag();
        }
        viewHolder.tv_type.setText(couponList.get(position).getType());
        viewHolder.tv_number.setText(couponList.get(position).getNumber());
        viewHolder.tv_time.setText(couponList.get(position).getTime());
        viewHolder.tv_meet.setText(couponList.get(position).getMeet());
        viewHolder.tv_use.setText(couponList.get(position).getUse());

        return convertView;
    }

    class CouponViewHolder {
        TextView tv_type;
        TextView tv_number;
        TextView tv_time;
        TextView tv_meet;
        TextView tv_use;
    }
}
